﻿using System;
using System.Collections.Generic;
using MyFloridaHouse.DataAccess;
using MyFloridaHouse.libSTO;
using MyFloridaHouse.libSvCommonUtilities;
using MyFloridaHouse.libSvDTO;

namespace MyFloridaHouse.libServiceBusinessRules
{
    public static class DistrictPlanTypes
    {
        public static DistrictPlanTypeSTO GetDistrictPlanTypes(DateTime clientFileTimestamp)
        {
			var results = new DistrictPlanTypeSTO();
			try
			{
                bool fileIsStale = true;
                try
                {
                    // check to see if the client data file is up to date
                    File.IsFileStale(clientFileTimestamp, Constants.CloudBlobBaseURL, Constants.CloudBlobContainer, Constants.CloudTimestampDirectory, Constants.CloudDistrictPlanTypesDataTimestampKey);
                }
                catch
                {
                    fileIsStale = true;
                }
                if (fileIsStale)
                {
                    var dal = new DAL_CensusData();
                    List<DistrictPlanTypeDTO> packList = dal.GetDistrictPlanTypes();
                    DistrictPlanTypeListDTO dtoList = new DistrictPlanTypeListDTO();
                    dtoList.districtPlanTypeList = packList;
                    byte[] serializedList = Serializer.Serialize(dtoList);
                    byte[] serializedAndCompressedList = CompressionManager.Compress(serializedList);
                    results.packedDataList = serializedAndCompressedList;
                }
			}
			catch (Exception ex)
			{
			    results.errorMessage = "Can not download DistrictPlanFile Types data : " + ex.Message;
			}
			return results;		
		}
    }
}
